package com.monkeygroup.mygoplus.view.home.activity.rent;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jude.rollviewpager.OnItemClickListener;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.LoopPagerAdapter;
import com.jude.rollviewpager.hintview.ColorPointHintView;
import com.monkeygroup.mygoplus.R;
import com.monkeygroup.mygoplus.base.BaseActivity;
import com.monkeygroup.mygoplus.commit.thing.vo.PropertyCommitVO;
import com.monkeygroup.mygoplus.common.DefinedView.CustomTextWatcher;
import com.monkeygroup.mygoplus.common.DefinedView.MyAlertDialog;
import com.monkeygroup.mygoplus.common.DefinedView.PickerView;
import com.monkeygroup.mygoplus.common.imageview.ImageLoader;
import com.monkeygroup.mygoplus.common.utils.LocalInfo;
import com.monkeygroup.mygoplus.common.utils.StringUtil;
import com.monkeygroup.mygoplus.common.utils.Tools;
import com.monkeygroup.mygoplus.http.RequestUrl;
import com.monkeygroup.mygoplus.http.ThingsHttpModel;
import com.monkeygroup.mygoplus.thing.vo.ChooseImgVO;
import com.monkeygroup.mygoplus.thing.vo.RentVO;
import com.monkeygroup.mygoplus.thing.vo.ThingImageVO;
import com.monkeygroup.mygoplus.thing.vo.ZoneVO;
import com.monkeygroup.mygoplus.view.home.activity.PublishedChooseAddrActivity;
import com.monkeygroup.mygoplus.view.home.activity.PublishedChooseImageActivity;
import com.monkeygroup.mygoplus.view.home.activity.PublishedChooseShopEquipActivity;
import com.monkeygroup.mygoplus.view.home.activity.PublishedImageActivity;
import com.monkeygroup.mygoplus.view.home.activity.ThingsDetailActivity;
import com.monkeygroup.mygoplus.view.home.activity.sell.PublishedActivity;
import com.monkeygroup.mygoplus.view.home.activity.sell.PublishedShopActivity;


import java.io.InputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * 新增出租辦公室物件
 * Created by cumt on 2017/5/27.
 */

public class PublishedRentOfficeActivity extends BaseActivity implements View.OnClickListener{

    public static void gotoActivity(Activity activity,String parent, String type) {
        Intent intent = new Intent(activity,
                PublishedRentOfficeActivity.class);

        intent.putExtra("type", type);
        intent.putExtra("parent", parent);

        activity.startActivity(intent);
    }

    private TextView txtHouse,txtModal,choose_month_unit,choose_year_unit;
    private EditText etName,etAddr,etAlley,etLane,etGate,etStorey,etOffices,etCommunity,etSellprice,etManagerprice;

    private EditText etStoreyNum,etStoreyTall,et_descrip,etSquare;
    private LinearLayout layout_shortcut,llMonthPrice,llRoomAge,llFitting,llBottomSee,llLayouttype,llPropertyBottom;

    private TextView spinner_month_price,spinner_room_age,spinner_fitting,spinner_layouttype,picker_rent_unit,spinner_deposit,rentcontain;

    private CheckBox check_room_age,check_finish_date,check_lift,check_carport,check_addr;
    private RelativeLayout relImage;
    private LinearLayout ll_img_item,ll_img,ll_community;

    private ThingsHttpModel propertyModel,communityHttpModel;
    private PropertyCommitVO requestVO;
    private Map<String,String> params;

    private ImageView focusDown,focusUp,myfocusDown,myfocusUp;

    private String type;
    private String parent;

    private PopupWindow pop,communitypop,pickerpop;
    private PickerView picker,choose_month_picker;

    private ImageView imgBack;
    private TextView txtTitle;
    private Activity activity;

    private List<RentVO> communityList;
    private CommunityAdapter communityAdapter;

    private Map<String,ChooseImgVO> chooseImg;
    //选择的图片类别
    private Map<String,ThingImageVO> mytype=null;

    @Override
    public void onClick(View v) {

    }

    @Override
    public void setContentView() {
        setContentView(R.layout.published_rent_offices_content);
    }

    @Override
    public void initView() {

        //   requestVO = new PropertyCommitVO();
//        Log.e("alInfo.getHou::;",""+LocalInfo.getHouseProperty(PublishedActivity.this));
        layout_shortcut= (LinearLayout) findViewById(R.id.layout_shortcut);
        layout_shortcut.setVisibility(View.INVISIBLE);
        activity = PublishedRentOfficeActivity.this;
        imgBack = (ImageView) findViewById(R.id.img_back);
        txtTitle = (TextView) findViewById(R.id.txt_title);

        txtTitle.setText("出租物件");

        //   Log.e("requesroperty_purpose==", "initView: "+ requestVO.getProperty_purpose());
        //   params=requestVO.toMap();

        txtHouse=(TextView)findViewById(R.id.txt_house);
        txtModal = (TextView) findViewById(R.id.txt_modal);
        etName =(EditText) findViewById(R.id.et_name);
        etAddr=(EditText) findViewById(R.id.et_addr);

        etAlley = (EditText)findViewById(R.id.et_alley);
        etLane=  (EditText)findViewById(R.id.et_lane);
        etGate= (EditText)findViewById(R.id.et_gate);

        etStorey = (EditText)findViewById(R.id.et_storey);
        etOffices = (EditText)findViewById(R.id.et_offices);
        etCommunity = (EditText)findViewById(R.id.et_community);
        etSellprice= (EditText) findViewById(R.id.et_sellprice);
        etManagerprice= (EditText) findViewById(R.id.et_managerprice);
        llMonthPrice = (LinearLayout)findViewById(R.id.ll_month_price);
        etStoreyNum = (EditText)findViewById(R.id.et_storey_num);
        etStoreyTall = (EditText)findViewById(R.id.et_storey_tall);

        etSquare= (EditText)findViewById(R.id.et_square);
        relImage= (RelativeLayout) findViewById(R.id.rel_image);

        spinner_month_price=(TextView)findViewById(R.id.spinner_month_price);
        spinner_room_age=(TextView)findViewById(R.id.spinner_room_age);
        spinner_fitting=(TextView)findViewById(R.id.spinner_fitting);
        spinner_layouttype=(TextView)findViewById(R.id.spinner_layouttype);


        check_room_age=(CheckBox) findViewById(R.id.check_room_age);
        check_finish_date=(CheckBox)findViewById(R.id.check_finish_date);
        check_lift=(CheckBox)findViewById(R.id.check_lift);
        check_carport=(CheckBox)findViewById(R.id.check_carport);
        check_addr=(CheckBox)findViewById(R.id.check_addr);


        llRoomAge= (LinearLayout)  findViewById(R.id.ll_room_age);
        llFitting = (LinearLayout)findViewById(R.id.ll_fitting);
        llPropertyBottom= (LinearLayout)findViewById(R.id.ll_property_bottom);


        llLayouttype= (LinearLayout) findViewById(R.id.ll_layouttype);
        picker_rent_unit=(TextView)findViewById(R.id.picker_rent_unit);
        spinner_deposit=(TextView)findViewById(R.id.spinner_deposit);
        rentcontain=(TextView)findViewById(R.id.spinner_rentcontain);

        et_descrip = (EditText)findViewById(R.id.et_descrip);
        llBottomSee= (LinearLayout) findViewById(R.id.ll_bottom_see);

        myfocusDown= (ImageView) findViewById(R.id.focus_down);
        myfocusUp= (ImageView) findViewById(R.id.focus_up);

        picker = (PickerView)findViewById(R.id.choose_picker);

        ll_img_item= (LinearLayout)findViewById(R.id.ll_img_item);
        ll_img= (LinearLayout)findViewById(R.id.ll_img);
        ll_community= (LinearLayout)findViewById(R.id.ll_community);

        communityList = new ArrayList<RentVO>();
        params = new HashMap<>();
        chooseImg=new HashMap<>();
        mytype= new HashMap<String,ThingImageVO>();


        Intent intent = this.getIntent();
        Bundle bundle =  intent.getExtras();
        type = bundle.getString("type");
        parent= bundle.getString("parent");

        initData();
        fillData();
        initCheck();
        initRequest();
        initWatcher();
        initPopwindow();
        initPickerPopwindow();
        initCommunityPopwindow();

        communityHttpModel.communityRequestThings();


    }

    private void initData(){
        Log.e("parentparent==",""+parent+type);
        if("1".equals(parent)){
            txtHouse.setText("住宅");
            requestVO= LocalInfo.getHouseProperty(PublishedRentOfficeActivity.this,type);
            if(requestVO.getProperty_purpose()==null){
                requestVO.setProperty_purpose("house");
            }

            if("0".equals(type)){
                txtModal.setText("公寓");
            }
            else if("1".equals(type)){
                txtModal.setText("電梯大樓");
            }
            else if("2".equals(type)){
                txtModal.setText("電梯大樓（飯店式管理）");
            }
            else if("3".equals(type)){
                txtModal.setText("豪宅");
            }
            else if("4".equals(type)){
                txtModal.setText("別墅");
            }
            else if("5".equals(type)){
                txtModal.setText("套房");
            }
            else if("6".equals(type)){
                txtModal.setText("四合院");
            }
            else if("7".equals(type)){
                txtModal.setText("平房");
            }
            else if("8".equals(type)){
                txtModal.setText("透天厝");
            }
            else if("9".equals(type)){
                txtModal.setText("樓中樓");
            }
            else if("10".equals(type)){
                txtModal.setText("其他");
            }
        }
        else if("3".equals(parent)){
            txtHouse.setText("辦公室");
            requestVO=LocalInfo.getRentOfficeProperty(PublishedRentOfficeActivity.this,type);
            if(StringUtil.isBlank(requestVO.getProperty_purpose())){
                requestVO.setProperty_purpose("office");
            }
            requestVO.setProperty_modal(Integer.parseInt(type));


            if("0".equals(type)){
                txtModal.setText("純辦公大樓");
            }
            else if("1".equals(type)){
                txtModal.setText("住辦兩用");
            }
            else if("2".equals(type)){
                txtModal.setText("店住辦");
            }
            else if("3".equals(type)){
                txtModal.setText("工業住辦");
            }
            else if("4".equals(type)){
                txtModal.setText("其他");
            }


        }
        else if("4".equals(parent)){

            txtHouse.setText("廠房");
            requestVO=LocalInfo.getRentWorkshopProperty(PublishedRentOfficeActivity.this,type);
            if(StringUtil.isBlank(requestVO.getProperty_purpose())){
                requestVO.setProperty_purpose("workshop");
            }
            requestVO.setProperty_modal(Integer.parseInt(type));
            if("0".equals(type)){
                txtModal.setText("純厰房");
            }
            else if("1".equals(type)){
                txtModal.setText("厰房厰辦");
            }
            else if("2".equals(type)){
                txtModal.setText("倉庫");
            }
            else if("3".equals(type)){
                txtModal.setText("其他");
            }
        }


    }

    private void fillData(){

        etName.setText(requestVO.getProperty_name());

        if(requestVO.getProperty_alley()!=0){
            etAlley.setText(String.valueOf(requestVO.getProperty_alley()));
        }
        if(requestVO.getProperty_lane()!=0){
            etLane.setText(String.valueOf(requestVO.getProperty_lane()));
        }
        if(requestVO.getProperty_gate()!=0){
            etGate.setText(String.valueOf(requestVO.getProperty_gate()));
        }
        //几楼
        //    Log.e("Strroperty_floor())楼==",""+String.valueOf(requestVO.getProperty_floor()));
        if(requestVO.getProperty_floor()!=0){
            etStorey.setText(String.valueOf(requestVO.getProperty_floor()));
        }
        //几室
        if(requestVO.getProperty_room()!=0){
            etOffices.setText(String.valueOf(requestVO.getProperty_room()));
        }
        //租金
        if(requestVO.getProperty_saleprice()!=0){
            etSellprice.setText(String.valueOf(requestVO.getProperty_saleprice()));
        }
        //楼层
        if(requestVO.getProperty_minfloor()!=0){
            etStoreyNum.setText(String.valueOf(requestVO.getProperty_minfloor()));
        }
        //楼高
        if(requestVO.getProperty_totalfloor()!=0){
            etStoreyTall.setText(String.valueOf(requestVO.getProperty_totalfloor()));
        }
        //坪数
        if(requestVO.getProperty_ownershiparea()!=0){
            etSquare.setText(String.valueOf(requestVO.getProperty_ownershiparea()));
        }

        if(!StringUtil.isBlank(String.valueOf(requestVO.getProperty_desc()))){
            et_descrip.setText(String.valueOf(requestVO.getProperty_desc()));
        }
        if(requestVO.getProperty_fee()!=0){
            etManagerprice.setText(String.valueOf(requestVO.getProperty_fee()));
        }
        //隐藏门号
        if(requestVO.getProperty_hidegate()==1){
            check_addr.setChecked(true);
        }
        else{
            check_addr.setChecked(false);
        }
        //完工日期
        if(!StringUtil.isBlank(requestVO.getProperty_completedate())){
            check_finish_date.setChecked(true);
            check_room_age.setChecked(false);
        }
        else{
            check_finish_date.setChecked(false);
            check_room_age.setChecked(true);
        }

        //电梯
        if(requestVO.getProperty_lift()==1){
            check_lift.setChecked(true);
        }
        else{
            check_lift.setChecked(false);
        }
        //车位
        if(requestVO.getProperty_carport()==1){
            check_carport.setChecked(true);
        }
        else{
            check_carport.setChecked(false);
        }

        //租金包含
        if(!StringUtil.isBlank(requestVO.getProperty_rentcontain())){
            //押金方式
            if("5".equals(requestVO.getProperty_rentcontain())){
                rentcontain.setText("電費");
            }
            else if("2".equals(requestVO.getProperty_rentcontain())){
                rentcontain.setText("第四台");
            }
            else if("3".equals(requestVO.getProperty_rentcontain())){
                rentcontain.setText("網路");
            }
            else if("4".equals(requestVO.getProperty_rentcontain())){
                rentcontain.setText("瓦斯費");
            }
            else if("6".equals(requestVO.getProperty_rentcontain())){
                rentcontain.setText("水費");
            }
        }

        //       Log.e("requestVO.getPreetype()",""+requestVO.getProperty_feetype());
//        //管理费类型
        if(requestVO.getProperty_feetype()==1){
            spinner_month_price.setText("無");
        }
        else if(requestVO.getProperty_feetype()==2){
            spinner_month_price.setText("每坪");
        }
        else if(requestVO.getProperty_feetype()==8){
            spinner_month_price.setText("每平米");
        }
        else if(requestVO.getProperty_feetype()==3){
            spinner_month_price.setText("月費");
        }
        else if(requestVO.getProperty_feetype()==4){
            spinner_month_price.setText("季費");
        }
        else if(requestVO.getProperty_feetype()==5){
            spinner_month_price.setText("年費");
        }
        else if(requestVO.getProperty_feetype()==6){
            spinner_month_price.setText("房東負責");
        }
        else if(requestVO.getProperty_feetype()==7){
            spinner_month_price.setText("其他");
        }
//        //裝修
        if(requestVO.getProperty_fitting()==1){
            spinner_fitting.setText("毛坯");
        }
        else if(requestVO.getProperty_fitting()==2){
            spinner_fitting.setText("普通裝修");
        }
        else if(requestVO.getProperty_fitting()==3){
            spinner_fitting.setText("精裝修");
        }
        else if(requestVO.getProperty_fitting()==4){
            spinner_fitting.setText("豪華裝修");
        }

        //租金方式
        if(requestVO.getProperty_renttype()==1) {
            picker_rent_unit.setText("月費");
        }
        else if(requestVO.getProperty_renttype()==2) {
            picker_rent_unit.setText("日費");
        }
        else if(requestVO.getProperty_renttype()==3) {
            picker_rent_unit.setText("年費");
        }
        else if(requestVO.getProperty_renttype()==4) {
            picker_rent_unit.setText("半年費");
        }
        else if(requestVO.getProperty_renttype()==5) {
            picker_rent_unit.setText("季費");
        }
        else if(requestVO.getProperty_renttype()==6) {
            picker_rent_unit.setText("每學期");
        }
        else if(requestVO.getProperty_renttype()==7) {
            picker_rent_unit.setText("每學年");
        }
        else if(requestVO.getProperty_renttype()==8) {
            picker_rent_unit.setText("每坪費用");
        }
        else if(requestVO.getProperty_renttype()==9) {
            picker_rent_unit.setText("每平米費用");
        }else if(requestVO.getProperty_renttype()==10) {
            picker_rent_unit.setText("其他");
        }

        //押金方式
        if(requestVO.getProperty_deposittype()==1){
            spinner_deposit.setText("一個月租金");

        }
        else if(requestVO.getProperty_deposittype()==2){
            spinner_deposit.setText("兩個月租金");
        }
        else if(requestVO.getProperty_deposittype()==3){
            spinner_deposit.setText("三個月租金");
        }
        else if(requestVO.getProperty_deposittype()==4){
            spinner_deposit.setText("四個月租金");
        }
        else if(requestVO.getProperty_deposittype()==5){
            spinner_deposit.setText("五個月租金");
        }
        else if(requestVO.getProperty_deposittype()==6){
            spinner_deposit.setText("六個月租金");
        }
        else if(requestVO.getProperty_deposittype()==7){
            spinner_deposit.setText("一年租金");
        }else if(requestVO.getProperty_deposittype()==8){
            spinner_deposit.setText("其他");
        }


        //坐向
        if(requestVO.getProperty_direction()==1){
            spinner_layouttype.setText("坐北朝南");
        }
        else if(requestVO.getProperty_direction()==2){
            spinner_layouttype.setText("坐南朝北");
        }
        else if(requestVO.getProperty_direction()==3){
            spinner_layouttype.setText("坐西朝東");
        }
        else if(requestVO.getProperty_direction()==4){
            spinner_layouttype.setText("坐東朝西");
        }
        else if(requestVO.getProperty_direction()==5){
            spinner_layouttype.setText("坐東北朝西南");
        }
        else if(requestVO.getProperty_direction()==6){
            spinner_layouttype.setText("坐東南朝西北");
        }
        else if(requestVO.getProperty_direction()==7){
            spinner_layouttype.setText("坐西南朝東北");
        }
        else if(requestVO.getProperty_direction()==8){
            spinner_layouttype.setText("坐西北朝東南");
        }
        else if(requestVO.getProperty_direction()==9){
            spinner_layouttype.setText("其他");
        }
        //图片

        if(requestVO.getPropertyimg_sceimgtype()!=null && requestVO.getPropertyimg_sceimgtype().length!=0){
            //  Log.e("requestVOgtype()",""+requestVO.getPropertyimg_sceimgtype().length);
            String[] imgs = new String[3];
            imgs[0]="";
            fillImg(imgs);
        }

        //地址
        if(requestVO.getProperty_city()!=0){
            InputStream cityinputStream = getResources().openRawResource(R.raw.city);
            List<ZoneVO> cityVOs = Tools.getString("15801",cityinputStream,"",String.valueOf(requestVO.getProperty_city()));
            //  Log.e("requestPrty()==",""+requestVO.getProperty_city()+"++"+cityVOs.size());
            if(requestVO.getProperty_area()!=0){
                InputStream areainputStream = getResources().openRawResource(R.raw.area);
                List<ZoneVO> areaVOs = Tools.getString(cityVOs.get(0).getId(),areainputStream,"",String.valueOf(requestVO.getProperty_area()));
                etAddr.setText(cityVOs.get(0).getName()+areaVOs.get(0).getName());
                Log.e("requestPrty()==",""+requestVO.getProperty_street()+"++"+cityVOs.size());
                if(!StringUtil.isBlank(requestVO.getProperty_street())){
                    InputStream streetinputStream = getResources().openRawResource(R.raw.street);
                    List<ZoneVO> streetVOs = Tools.getString(areaVOs.get(0).getId(),streetinputStream,"",String.valueOf(requestVO.getProperty_street()));
                    if(streetVOs.size()>0){
                        etAddr.setText(cityVOs.get(0).getName()+areaVOs.get(0).getName()+streetVOs.get(0).getName());
                    }

                }
            }

        }


    }

    private void fillImg(String[] imgs){

        ll_img_item.setVisibility(View.VISIBLE);
        String[] image = null;

//        ll_img.removeAllViews();
        Log.e("getPropertysceimgtype==",""+requestVO.getPropertyimg_sceimgtype().length);
        for(int i=0;i<requestVO.getPropertyimg_sceimgtype().length;i++){
            if(!StringUtil.isBlank(requestVO.getPropertyimg_sceimgtype()[i])){
//                Log.e("getProperimgtype111==",""+(requestVO.getPropertyimg_sceimgtype()[i]==null));
//                Log.e("getProperimgtype111==",""+(requestVO.getPropertyimg_sceimgtype()[i]));
                FrameLayout content = new FrameLayout(activity);
                FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 220);
                lp.setMargins(40,40,0,10);
                content.setLayoutParams(lp);

                TextView txt = new TextView(activity);
                FrameLayout.LayoutParams txtlp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                txtlp.setMargins(20,0,0,10);
                txtlp.gravity=Gravity.BOTTOM;
                txt.setLayoutParams(txtlp);

                RollPagerView pagerView = new RollPagerView(activity);

                ChooseImgVO img = new ChooseImgVO();

                if(imgs==null || imgs.length==0){
                    image=mytype.get(requestVO.getPropertyimg_sceimgtype()[i]).getImg();

                    if(chooseImg.get(requestVO.getPropertyimg_sceimgtype()[i])==null){

                        img.setFrameLayout(content);
                        img.setTextView(txt);
                        img.setPagerView(pagerView);
                        chooseImg.put(requestVO.getPropertyimg_sceimgtype()[i],img);

                    }
                    else{
                        content=chooseImg.get(requestVO.getPropertyimg_sceimgtype()[i]).getFrameLayout();
                        txt=chooseImg.get(requestVO.getPropertyimg_sceimgtype()[i]).getTextView();
                        pagerView=chooseImg.get(requestVO.getPropertyimg_sceimgtype()[i]).getPagerView();
                    }

                    requestVO.setPropertyimg_path2(image);
                }
                else{
                    img.setFrameLayout(content);
                    img.setTextView(txt);
                    img.setPagerView(pagerView);
                    chooseImg.put("1",img);
                    image=requestVO.getPropertyimg_path2();
                }

                if("0".equals(requestVO.getPropertyimg_sceimgtype()[i])){
                    txt.setText("社區實景圖");
                }
                else if("1".equals(requestVO.getPropertyimg_sceimgtype()[i])){
                    txt.setText("效果圖");
                }
                else if("2".equals(requestVO.getPropertyimg_sceimgtype()[i])){
                    txt.setText("規劃圖");
                }
                else if("3".equals(requestVO.getPropertyimg_sceimgtype()[i])){
                    txt.setText("位置圖");
                }
                else if("4".equals(requestVO.getPropertyimg_sceimgtype()[i])){
                    txt.setText("生活機能圖");
                }
                else if("5".equals(requestVO.getPropertyimg_sceimgtype()[i])){
                    txt.setText("樣品屋圖");
                }
                else if("6".equals(requestVO.getPropertyimg_sceimgtype()[i])){
                    txt.setText("室內實景圖");
                }

                txt.setTextColor(getResources().getColor(R.color.white));
                if(image!=null && image.length!=0){
                    pagerView.setAdapter(new ImageLoopAdapter(pagerView,image,requestVO.getPropertyimg_sceimgtype()[i]));
                }


                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    pagerView.setHintView(new ColorPointHintView(activity, Color.parseColor("#DC473A"),Color.parseColor("#88ffffff")));
                }
                pagerView.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(int position) {
                        //   Toast.makeText(PublishedActivity.this,"图片 "+position+" clicked",Toast.LENGTH_SHORT).show();
                    }
                });

                if(content.getChildCount()!=0){
                    content.removeAllViews();

                    content.addView(pagerView);
                    content.addView(txt);
                }
                else{
                    content.addView(pagerView);
                    content.addView(txt);

                    ll_img.addView(content);
                }
            }

        }

        if(imgs==null || imgs.length==0){
            LocalInfo.saveProperty(activity,requestVO);
        }

    }

    private void initCheck(){
// if(check_room_age.isChecked()){
        check_addr.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    requestVO.setProperty_hidegate(1);
                    LocalInfo.saveRentProperty(activity,requestVO);
                }
            }
        });

        check_finish_date.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    check_room_age.setChecked(false);
                    //   requestVO.setProperty_completedate(spinner_room_age.getText());

                }
            }
        });
        //  }
        check_room_age.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    check_finish_date.setChecked(false);

                }
            }
        });
        check_lift.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    check_carport.setChecked(false);
                    requestVO.setProperty_lift(1);
                    requestVO.setProperty_carport(0);
                    LocalInfo.saveRentProperty(activity,requestVO);
                }
            }
        });
        check_carport.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    check_lift.setChecked(false);
                    requestVO.setProperty_carport(1);
                    requestVO.setProperty_lift(0);
                    LocalInfo.saveRentProperty(activity,requestVO);
                }
            }
        });
    }

    private void initRequest(){

        propertyModel = new ThingsHttpModel(RequestUrl.savepropertyUrl, params ,
                new ThingsHttpModel.SimpleOnHttpRequestListener() {

                    @Override
                    public void onRequestFinished(String resultCode, Integer timestamp) {

                    }

                    @Override
                    public void onRequestFinished(String resultCode, Object property, Object user, Object users, Object circuit, Object img) {

                    }

                    @Override
                    public void onBuildingRequestFinished(String resultCode, Object building, Object user, Object users, Object circuit, Object img) {

                    }

                    @Override
                    public void onCommunityRequestFinished(String resultCode, Object community, Object user, Object users, Object circuit, Object img) {

                    }
                }
                ,true);

        communityHttpModel= new ThingsHttpModel(RequestUrl.communityUrl, params ,
                new ThingsHttpModel.SimpleOnHttpRequestListener() {

                    @Override
                    public void onRequestFinished(String resultCode, Integer timestamp) {

                    }

                    @Override
                    public void onRequestFinished(String resultCode, Object property, Object user, Object users, Object circuit, Object img) {

                    }

                    @Override
                    public void onBuildingRequestFinished(String resultCode, Object building, Object user, Object users, Object circuit, Object img) {

                    }

                    @Override
                    public void onCommunityRequestFinished(String resultCode, Object community, Object user, Object users, Object circuit, Object img) {
                        communityList.clear();
                        Gson gson = new Gson();
                        List<RentVO>  model = gson.fromJson(gson.toJson(community), new TypeToken<List<RentVO>>() {}.getType());
//                        for(RentVO vo :model){
                        communityList.addAll(model);
//                        }


                    }
                }
                ,true);
    }
    private void initWatcher(){

        TextWatcher nwname=new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {


            }

            @Override
            public void afterTextChanged(Editable s) {
                if(etName.getText().length()>10){
                    MyAlertDialog dialog = new MyAlertDialog(PublishedRentOfficeActivity.this,"物件名稱不能超過10個漢字",String.valueOf(etName.getText()));
                    dialog.show(PublishedRentOfficeActivity.this,"物件名稱不能超過10個漢字",1);
                }
                else{
                    if(!StringUtil.isBlank(String.valueOf(etName.getText()))){
                        requestVO.setProperty_name(String.valueOf(etName.getText()));
                        LocalInfo.saveRentProperty(PublishedRentOfficeActivity.this,requestVO);
                    }
                }


            }
        };
        etName.addTextChangedListener(nwname);
        etName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                //得到焦點
                if (hasFocus) {
                    llPropertyBottom.setVisibility(View.VISIBLE);
                    picker.setVisibility(View.GONE);

                }

            }
        });



        TextWatcher cname=new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                if (communitypop != null && communitypop.isShowing()) {
//                    communitypop.dismiss();
//                } else {
                ll_community.setBackgroundResource(R.drawable.community_shape);
                if(!StringUtil.isBlank(String.valueOf(etCommunity.getText()))){

                    params.put("searchKey",String.valueOf(etCommunity.getText()));
                }
                communityHttpModel.communityRequestThings();
                communityAdapter.notifyDataSetChanged();
                communitypop.showAsDropDown(etCommunity);
//                }

            }

            @Override
            public void afterTextChanged(Editable s) {

                ll_community.setBackgroundResource(R.drawable.edit_community_shape);


            }
        };
        etCommunity.addTextChangedListener(cname);




    }

    @Override
    public void setListener() {

        etLane.addTextChangedListener(new CustomTextWatcher(activity,etLane,requestVO,2,false));
        etAlley.addTextChangedListener(new CustomTextWatcher(activity,etAlley,requestVO,1,false));
        etGate.addTextChangedListener(new CustomTextWatcher(activity,etGate,requestVO,3,false));
        etStorey.addTextChangedListener(new CustomTextWatcher(activity,etStorey,requestVO,4,false));
        etOffices.addTextChangedListener(new CustomTextWatcher(activity,etOffices,requestVO,5,false));
        //售价
        etSellprice.addTextChangedListener(new CustomTextWatcher(activity,etSellprice,requestVO,6,false));
        //楼层
        etStoreyNum.addTextChangedListener(new CustomTextWatcher(activity,etStoreyNum,requestVO,7,false));
        //楼高
        etStoreyTall.addTextChangedListener(new CustomTextWatcher(activity,etStoreyTall,requestVO,8,false));
        //坪数
        etSquare.addTextChangedListener(new CustomTextWatcher(activity,etSquare,requestVO,9,false));

        et_descrip.addTextChangedListener(new CustomTextWatcher(activity,et_descrip,requestVO,15,false));
        etManagerprice.addTextChangedListener(new CustomTextWatcher(activity,etManagerprice,requestVO,16,false));

        etAddr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PublishedChooseAddrActivity.gotoActivity(activity,"1");

            }
        });
        relImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                PublishedChooseImageActivity.gotoActivity(activity);

            }
        });

        myfocusDown.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View rootview = activity.getWindow().getDecorView();
                View focus = rootview.findFocus();
                if(findViewById(focus.getNextFocusDownId())!=null && focus.getNextFocusDownId()!=0){
                    findViewById(focus.getNextFocusDownId()).requestFocus();
                }


            }
        });
        myfocusUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View rootview = activity.getWindow().getDecorView();
                View focus = rootview.findFocus();
                if(findViewById(focus.getNextFocusDownId())!=null && focus.getNextFocusUpId()!=0){
                    findViewById(focus.getNextFocusUpId()).requestFocus();
                }


            }
        });

        spinner_month_price.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

//                llPropertyBottom.setVisibility(View.VISIBLE);
//                picker.setVisibility(View.VISIBLE);

                choose_month_picker.setVisibility(View.GONE);
                choose_month_unit.setVisibility(View.GONE);
                choose_year_unit.setVisibility(View.GONE);

                etManagerprice.requestFocus();
                focusDown.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        View rootview = activity.getWindow().getDecorView();
                        View focus = rootview.findFocus();
                        //   Log.e("focus.getNextFownId()=",""+focus.getNextFocusDownId());
                        if(findViewById(focus.getNextFocusDownId())!=null && focus.getNextFocusDownId()!=0){
                            findViewById(focus.getNextFocusDownId()).requestFocus();
                        }


                    }
                });
                focusUp.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        View rootview = activity.getWindow().getDecorView();
                        View focus = rootview.findFocus();
                        //   Log.e("focus.getNextFownId()=",""+focus.getNextFocusDownId());
                        if(findViewById(focus.getNextFocusUpId())!=null && focus.getNextFocusUpId()!=0){
                            findViewById(focus.getNextFocusUpId()).requestFocus();
                        }


                    }
                });
                if (pickerpop != null && pickerpop.isShowing()) {
                    pickerpop.dismiss();
                } else {
                    pickerpop.showAtLocation(getCurrentFocus(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                }
                List<String> monthPrice = new ArrayList<String>();
                //property_feetype 1
                monthPrice.add("無");
                //2
                monthPrice.add("每坪");
                //8
                monthPrice.add("每平米");
                //3
                monthPrice.add("月費");
                //4
                monthPrice.add("季費");
                //5
                monthPrice.add("年費");
                //6
                monthPrice.add("房東負責");
                //7
                monthPrice.add("其他");

                picker.setData(monthPrice);

                //管理费类型
                if(requestVO.getProperty_feetype()==1){
                    picker.setSelected(0);
                }
                else if(requestVO.getProperty_feetype()==2){
                    picker.setSelected(1);
                }
                else if(requestVO.getProperty_feetype()==8){
                    picker.setSelected(2);
                }
                else if(requestVO.getProperty_feetype()==3){
                    picker.setSelected(3);
                }
                else if(requestVO.getProperty_feetype()==4){
                    picker.setSelected(4);
                }
                else if(requestVO.getProperty_feetype()==5){
                    picker.setSelected(5);
                }
                else if(requestVO.getProperty_feetype()==6){
                    picker.setSelected(6);
                }
                else if(requestVO.getProperty_feetype()==7){
                    picker.setSelected(7);
                }


                picker.setOnSelectListener(new PickerView.onSelectListener()
                {

                    @Override
                    public void onSelect(String text)
                    {
                        spinner_month_price.setText(text);
                        if("無".equals(text)){
                            requestVO.setProperty_feetype(1);
                        }
                        else if("每坪".equals(text)){
                            requestVO.setProperty_feetype(2);
                        }
                        else if("每平米".equals(text)){
                            requestVO.setProperty_feetype(8);
                        }
                        else if("月費".equals(text)){
                            requestVO.setProperty_feetype(3);
                        }
                        else if("季費".equals(text)){
                            requestVO.setProperty_feetype(4);
                        }else if("年費".equals(text)){
                            requestVO.setProperty_feetype(5);

                        }else if("房東負責".equals(text)){
                            requestVO.setProperty_feetype(6);

                        }else if("其他".equals(text)){
                            requestVO.setProperty_feetype(7);
                        }
                        LocalInfo.saveRentProperty(activity,requestVO);
                    }
                });

            }
        });
        spinner_month_price.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                //失去焦點
                if (!hasFocus) {
                    picker.setVisibility(View.GONE);
                }
                else{
                    picker.setVisibility(View.GONE);
                }
            }
        });

        spinner_room_age.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                etSquare.requestFocus();
                if (pickerpop != null && pickerpop.isShowing()) {
                    pickerpop.dismiss();
                } else {
                    pickerpop.showAtLocation(getCurrentFocus(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                }
                if(check_room_age.isChecked()) {
                    choose_month_picker.setVisibility(View.GONE);
                    choose_month_unit.setVisibility(View.GONE);
                    choose_year_unit.setVisibility(View.VISIBLE);
                    List<String> houseage = new ArrayList<String>();
                    for(int i=0;i<61;i++){
                        houseage.add(""+i);
                    }
                    picker.setData(houseage);
                    picker.setSelected(0);

                    picker.setOnSelectListener(new PickerView.onSelectListener()
                    {

                        @Override
                        public void onSelect(String text)
                        {
                            spinner_room_age.setText(text);
                            requestVO.setProperty_completeyear(Integer.parseInt(text.substring(0,1)));
                            LocalInfo.saveProperty(activity,requestVO);
                        }
                    });
                }
                //完工日期
                else if(check_finish_date.isChecked()){

                    final String[] chooseyear = new String[2];

                    choose_month_picker.setVisibility(View.VISIBLE);
                    choose_year_unit.setVisibility(View.VISIBLE);
                    choose_month_unit.setVisibility(View.VISIBLE);
                    Calendar a= Calendar.getInstance();
                    final int year = a.get(Calendar.YEAR);
                    List<String> completeDate = new ArrayList<String>();
                    for(int i=0;i<30;i++){
                        completeDate.add(String.valueOf(year+i));
                    }
                    picker.setData(completeDate);
                    picker.setSelected(0);
                    picker.setOnSelectListener(new PickerView.onSelectListener()
                    {

                        @Override
                        public void onSelect(String text)
                        {
                            chooseyear[0] =text;
                            if(StringUtil.isBlank(chooseyear[1])){
                                chooseyear[1]="1";
                            }
                            spinner_room_age.setText(chooseyear[0]+"-"+chooseyear[1]);
                            requestVO.setProperty_completedate(chooseyear[0]+"-"+chooseyear[1]);
                            LocalInfo.saveProperty(activity,requestVO);
                        }
                    });


                    //月份
                    List<String> completeMonth= new ArrayList<String>();
                    for(int i=0;i<12;i++){
                        completeMonth.add(String.valueOf(i+1));
                    }

                    choose_month_picker.setData(completeMonth);
                    choose_month_picker.setSelected(0);
                    choose_month_picker.setOnSelectListener(new PickerView.onSelectListener()
                    {

                        @Override
                        public void onSelect(String text)
                        {

                            if(StringUtil.isBlank(chooseyear[1])){
                                chooseyear[0]=String.valueOf(year);
                            }
                            chooseyear[1] =text;
                            spinner_room_age.setText(chooseyear[0]+"-"+chooseyear[1]);
                            requestVO.setProperty_completedate(chooseyear[0]+"-"+chooseyear[1]);
                            LocalInfo.saveProperty(activity,requestVO);
                        }
                    });



                }
            }
        });

        spinner_room_age.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                //失去焦點
                if (!hasFocus) {
                    picker.setVisibility(View.GONE);
                }
            }
        });
        //裝修
        spinner_fitting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                choose_month_picker.setVisibility(View.GONE);
                choose_month_unit.setVisibility(View.GONE);
                choose_year_unit.setVisibility(View.GONE);
//                llPropertyBottom.setVisibility(View.VISIBLE);
//                picker.setVisibility(View.VISIBLE);

                etSquare.requestFocus();
                if (pickerpop != null && pickerpop.isShowing()) {
                    pickerpop.dismiss();
                } else {
                    pickerpop.showAtLocation(getCurrentFocus(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                }
                List<String> fitting = new ArrayList<String>();

                fitting.add("毛坯");
                fitting.add("普通裝修");
                fitting.add("精裝修");
                fitting.add("豪華裝修");

                picker.setData(fitting);
                //裝修
                if(requestVO.getProperty_fitting()==1){
                    picker.setSelected(0);
                }
                else if(requestVO.getProperty_fitting()==2){
                    picker.setSelected(1);
                }
                else if(requestVO.getProperty_fitting()==3){
                    picker.setSelected(2);
                }
                else if(requestVO.getProperty_fitting()==4){
                    picker.setSelected(3);
                }

                picker.setOnSelectListener(new PickerView.onSelectListener()
                {

                    @Override
                    public void onSelect(String text)
                    {
                        spinner_fitting.setText(text);
                        if("毛坯".equals(text)){
                            requestVO.setProperty_fitting(1);
                        }
                        else if("普通裝修".equals(text)){
                            requestVO.setProperty_fitting(2);
                        }
                        else if("精裝修".equals(text)){
                            requestVO.setProperty_fitting(3);
                        }
                        else if("豪華裝修".equals(text)){
                            requestVO.setProperty_fitting(4);
                        }

                        LocalInfo.saveRentProperty(activity,requestVO);

                    }
                });
            }
        });
        spinner_fitting.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                //失去焦點
                if (!hasFocus) {
                    picker.setVisibility(View.GONE);
                }
            }
        });


        //租金單位
        picker_rent_unit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                choose_month_picker.setVisibility(View.GONE);
                choose_month_unit.setVisibility(View.GONE);
                choose_year_unit.setVisibility(View.GONE);
//                llPropertyBottom.setVisibility(View.VISIBLE);
//                picker.setVisibility(View.VISIBLE);
                etSquare.requestFocus();
                if (pickerpop != null && pickerpop.isShowing()) {
                    pickerpop.dismiss();
                } else {
                    pickerpop.showAtLocation(getCurrentFocus(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                }
                List<String> rentunit = new ArrayList<String>();

                rentunit.add("月費");
                rentunit.add("日費");
                rentunit.add("年費");
                rentunit.add("半年費");
                rentunit.add("季費");
                rentunit.add("每學期");
                rentunit.add("每學年");
                rentunit.add("每坪費用");
                rentunit.add("每平米費用");
                rentunit.add("其他");

                picker.setData(rentunit);
                //租金方式
                if (requestVO.getProperty_renttype() == 1) {
                    picker.setSelected(0);
                } else if (requestVO.getProperty_renttype() == 2) {
                    picker.setSelected(1);
                } else if (requestVO.getProperty_renttype() == 3) {
                    picker.setSelected(2);
                } else if (requestVO.getProperty_renttype() == 4) {
                    picker.setSelected(3);
                } else if (requestVO.getProperty_renttype() == 5) {
                    picker.setSelected(4);
                } else if (requestVO.getProperty_renttype() == 6) {
                    picker.setSelected(5);
                } else if (requestVO.getProperty_renttype() == 7) {
                    picker.setSelected(6);
                } else if (requestVO.getProperty_renttype() == 8) {
                    picker.setSelected(7);
                } else if (requestVO.getProperty_renttype() == 9) {
                    picker.setSelected(8);
                } else if (requestVO.getProperty_renttype() == 10) {
                    picker.setSelected(9);
                }

                picker.setOnSelectListener(new PickerView.onSelectListener() {

                    @Override
                    public void onSelect(String text) {
                        picker_rent_unit.setText(text);
                        if ("月費".equals(text)) {
                            requestVO.setProperty_renttype(1);
                        } else if ("日費".equals(text)) {
                            requestVO.setProperty_renttype(2);
                        } else if ("年費".equals(text)) {
                            requestVO.setProperty_renttype(3);
                        } else if ("半年費".equals(text)) {
                            requestVO.setProperty_renttype(4);
                        } else if ("季費".equals(text)) {
                            requestVO.setProperty_renttype(5);
                        } else if ("每學期".equals(text)) {
                            requestVO.setProperty_renttype(6);
                        } else if ("每學年".equals(text)) {
                            requestVO.setProperty_renttype(7);
                        } else if ("每坪費用".equals(text)) {
                            requestVO.setProperty_renttype(8);
                        } else if ("每平米費用".equals(text)) {
                            requestVO.setProperty_renttype(9);
                        } else if ("其他".equals(text)) {
                            requestVO.setProperty_renttype(10);
                        }

                        LocalInfo.saveRentProperty(activity, requestVO);

                    }
                });
            }
        });
        picker_rent_unit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                //失去焦點
                if (!hasFocus) {
                    picker.setVisibility(View.GONE);
                }
            }
        });

        //押金
        spinner_deposit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                choose_month_picker.setVisibility(View.GONE);
                choose_month_unit.setVisibility(View.GONE);
                choose_year_unit.setVisibility(View.GONE);
//                llPropertyBottom.setVisibility(View.VISIBLE);
//                picker.setVisibility(View.VISIBLE);
                etSquare.requestFocus();
                if (pickerpop != null && pickerpop.isShowing()) {
                    pickerpop.dismiss();
                } else {
                    pickerpop.showAtLocation(getCurrentFocus(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                }
                List<String> depositunit = new ArrayList<String>();

                depositunit.add("一個月租金");
                depositunit.add("兩個月租金");
                depositunit.add("三個月租金");
                depositunit.add("四個月租金");
                depositunit.add("五個月租金");
                depositunit.add("六個月租金");
                depositunit.add("一年租金");
                depositunit.add("其他");

                picker.setData(depositunit);
                //押金方式
                if(requestVO.getProperty_deposittype()==1){
                    picker.setSelected(0);
                }
                else if(requestVO.getProperty_deposittype()==2){
                    picker.setSelected(1);
                }
                else if(requestVO.getProperty_deposittype()==3){
                    picker.setSelected(1);
                }
                else if(requestVO.getProperty_deposittype()==4){
                    picker.setSelected(1);
                }
                else if(requestVO.getProperty_deposittype()==5){
                    picker.setSelected(1);
                }
                else if(requestVO.getProperty_deposittype()==6){
                    picker.setSelected(1);
                }
                else if(requestVO.getProperty_deposittype()==7){
                    picker.setSelected(1);
                }else if(requestVO.getProperty_deposittype()==8){
                    picker.setSelected(1);
                }


                picker.setOnSelectListener(new PickerView.onSelectListener() {

                    @Override
                    public void onSelect(String text) {
                        spinner_deposit.setText(text);
                        if ("一個月租金".equals(text)) {
                            requestVO.setProperty_deposittype(1);
                        }
                        else if ("兩個月租金".equals(text)) {
                            requestVO.setProperty_deposittype(2);
                        }
                        else if ("三個月租金".equals(text)) {
                            requestVO.setProperty_deposittype(3);
                        }
                        else if ("四個月租金".equals(text)) {
                            requestVO.setProperty_deposittype(4);
                        }
                        else if ("五個月租金".equals(text)) {
                            requestVO.setProperty_deposittype(5);
                        }
                        else if ("六個月租金".equals(text)) {
                            requestVO.setProperty_deposittype(6);
                        }
                        else if ("一年租金".equals(text)) {
                            requestVO.setProperty_deposittype(7);
                        }else if ("其他".equals(text)) {
                            requestVO.setProperty_deposittype(8);
                        }

                        LocalInfo.saveRentProperty(activity, requestVO);
                    }
                });
            }
        });

        spinner_deposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                //失去焦點
                if (!hasFocus) {
                    picker.setVisibility(View.GONE);
                }
            }
        });

        //租金包含
        rentcontain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                llPropertyBottom.setVisibility(View.VISIBLE);
//                picker.setVisibility(View.VISIBLE);
                choose_month_picker.setVisibility(View.GONE);
                choose_month_unit.setVisibility(View.GONE);
                choose_year_unit.setVisibility(View.GONE);
                etSquare.requestFocus();
                if (pickerpop != null && pickerpop.isShowing()) {
                    pickerpop.dismiss();
                } else {
                    pickerpop.showAtLocation(getCurrentFocus(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                }
                List<String> rentcontain1 = new ArrayList<String>();

                rentcontain1.add("電費");
                rentcontain1.add("第四台");
                rentcontain1.add("網路");
                rentcontain1.add("瓦斯費");
                rentcontain1.add("水費");


                picker.setData(rentcontain1);
                //押金方式
                if("5".equals(requestVO.getProperty_rentcontain())){
                    picker.setSelected(0);
                }
                else if("2".equals(requestVO.getProperty_rentcontain())){
                    picker.setSelected(1);
                }
                else if("3".equals(requestVO.getProperty_rentcontain())){
                    picker.setSelected(2);
                }
                else if("4".equals(requestVO.getProperty_rentcontain())){
                    picker.setSelected(3);
                }
                else if("6".equals(requestVO.getProperty_rentcontain())){
                    picker.setSelected(4);
                }

                picker.setOnSelectListener(new PickerView.onSelectListener() {

                    @Override
                    public void onSelect(String text) {
                        rentcontain.setText(text);
                        if ("電費".equals(text)) {
                            requestVO.setProperty_rentcontain("5");
                        }
                        else if ("第四台".equals(text)) {
                            requestVO.setProperty_rentcontain("2");
                        }
                        else if ("網路".equals(text)) {
                            requestVO.setProperty_rentcontain("3");
                        }
                        else if ("瓦斯費".equals(text)) {
                            requestVO.setProperty_rentcontain("4");
                        }
                        else if ("水費".equals(text)) {
                            requestVO.setProperty_rentcontain("6");
                        }
                        LocalInfo.saveRentProperty(activity, requestVO);


                    }
                });

            }
        });

        rentcontain.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                //失去焦點
                if (!hasFocus) {
                    picker.setVisibility(View.GONE);
                }
            }
        });

        //坐向
        spinner_layouttype.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                choose_month_picker.setVisibility(View.GONE);
                choose_month_unit.setVisibility(View.GONE);
                choose_year_unit.setVisibility(View.GONE);
//                llPropertyBottom.setVisibility(View.VISIBLE);
//                picker.setVisibility(View.VISIBLE);
                etSquare.requestFocus();
                if (pickerpop != null && pickerpop.isShowing()) {
                    pickerpop.dismiss();
                } else {
                    pickerpop.showAtLocation(getCurrentFocus(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                }
                List<String> layouttype = new ArrayList<String>();

                layouttype.add("坐北朝南");
                layouttype.add("坐南朝北");
                layouttype.add("坐西朝東");
                layouttype.add("坐東朝西");
                layouttype.add("坐東北朝西南");
                layouttype.add("坐東南朝西北");
                layouttype.add("坐西南朝東北");
                layouttype.add("坐西北朝東南");
                layouttype.add("其他");

                picker.setData(layouttype);
                //坐向
                if(requestVO.getProperty_direction()==1){
                    picker.setSelected(0);
                }
                else if(requestVO.getProperty_direction()==2){
                    picker.setSelected(1);
                }
                else if(requestVO.getProperty_direction()==3){
                    picker.setSelected(2);
                }
                else if(requestVO.getProperty_direction()==4){
                    picker.setSelected(3);
                }
                else if(requestVO.getProperty_direction()==5){
                    picker.setSelected(4);
                }
                else if(requestVO.getProperty_direction()==6){
                    picker.setSelected(5);
                }
                else if(requestVO.getProperty_direction()==7){
                    picker.setSelected(6);
                }
                else if(requestVO.getProperty_direction()==8){
                    picker.setSelected(7);
                }
                else if(requestVO.getProperty_direction()==9){
                    picker.setSelected(8);
                }

                picker.setOnSelectListener(new PickerView.onSelectListener()
                {

                    @Override
                    public void onSelect(String text)
                    {
                        spinner_layouttype.setText(text);
                        if("坐北朝南".equals(text)){
                            requestVO.setProperty_direction(1);
                        }
                        else if("坐南朝北".equals(text)){
                            requestVO.setProperty_direction(2);
                        }
                        else if("坐西朝東".equals(text)){
                            requestVO.setProperty_direction(3);
                        }
                        else if("坐東朝西".equals(text)){
                            requestVO.setProperty_direction(4);
                        }
                        else if("坐東北朝西南".equals(text)){
                            requestVO.setProperty_direction(5);
                        }
                        else if("坐東南朝西北".equals(text)){
                            requestVO.setProperty_direction(6);
                        }
                        else if("坐西南朝東北".equals(text)){
                            requestVO.setProperty_direction(7);
                        }
                        else if("坐西北朝東南".equals(text)){
                            requestVO.setProperty_direction(8);
                        }
                        else if("其他".equals(text)){
                            requestVO.setProperty_direction(9);
                        }
                        LocalInfo.saveRentProperty(activity,requestVO);

                    }
                });

            }
        });

        llBottomSee.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Boolean notice=false;
                if(StringUtil.isBlank(requestVO.getProperty_name())){
                    notice=true;
                    setFocus(etName,notice);
                }
                if(requestVO.getProperty_alley()==0){
                    notice=true;
                    setFocus(etAlley,notice);
                }
                if(requestVO.getProperty_lane()==0){
                    notice=true;
                    setFocus(etLane,notice);
                }
                if(requestVO.getProperty_gate()==0){
                    notice=true;
                    setFocus(etGate,notice);
                }
                //几楼
                //    Log.e("Strroperty_floor())楼==",""+String.valueOf(requestVO.getProperty_floor()));
                if(requestVO.getProperty_floor()==0){
                    notice=true;
                    setFocus(etStorey,notice);
                }
                //几室
                if(requestVO.getProperty_room()==0){
                    notice=true;
                    setFocus(etOffices,notice);
                }
                //售价
                if(requestVO.getProperty_saleprice()==0){
                    notice=true;
                    setFocus(etSellprice,notice);
                }
                //楼层
                if(requestVO.getProperty_minfloor()==0){
                    notice=true;
                    setFocus(etStoreyNum,notice);
                }
                //楼高
                if(requestVO.getProperty_totalfloor()==0){
                    notice=true;
                    setFocus(etStoreyTall,notice);
                }
                //坪数
                if(requestVO.getProperty_ownershiparea()==0){
                    notice=true;
                    setFocus(etSquare,notice);
                }

//                if(StringUtil.isBlank(String.valueOf(requestVO.getProperty_desc()))){
//                    et_descrip.setText(String.valueOf(requestVO.getProperty_desc()));
//                }
                if(requestVO.getProperty_fee()==0){
                    notice=true;
                    setFocus(etManagerprice,notice);
                }

                if(notice){

                    MyAlertDialog dialog = new MyAlertDialog(activity,"您尚未填寫完畢",String.valueOf(etName.getText()));
                    dialog.show(activity,"您尚未填寫完畢",1);
                }
                else{

                    ThingsDetailActivity.gotoActivity(activity,"1",parent,type,"");
                }

            }
        });



    }

    private static void setFocus(EditText edit,boolean notice){

        notice=true;
        edit.requestFocus();
        InputMethodManager imm=(InputMethodManager)edit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

        imm.toggleSoftInput(0,InputMethodManager.SHOW_FORCED);


    }


    private void initPopwindow(){
        LayoutInflater myinflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView=myinflater.inflate(R.layout.popwindow_picker, null);


        pop = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, true);

        pop.setTouchable(true);
        //  ColorDrawable dw = new ColorDrawable(getResources().getColor(R.color.backgroud_light_I));
        pop.setBackgroundDrawable(new BitmapDrawable());


    }

    private void initPickerPopwindow(){

        LayoutInflater myinflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView=myinflater.inflate(R.layout.popwindow_picker, null);


        pickerpop = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);

        pickerpop.setTouchable(true);

        focusDown = (ImageView)contentView.findViewById(R.id.focus_down);
        focusUp = (ImageView)contentView.findViewById(R.id.focus_up);

        picker= (PickerView)contentView.findViewById(R.id.choose_picker);
        choose_month_picker= (PickerView)contentView.findViewById(R.id.choose_month_picker);
        choose_year_unit= (TextView)contentView.findViewById(R.id.choose_year_unit);
        choose_month_unit= (TextView)contentView.findViewById(R.id.choose_month_unit);
        //  ColorDrawable dw = new ColorDrawable(getResources().getColor(R.color.backgroud_light_I));
        pickerpop.setBackgroundDrawable(new BitmapDrawable());

    }

    private void initCommunityPopwindow(){
        LayoutInflater myinflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView=myinflater.inflate(R.layout.popwindow_community, null);


        communitypop = new PopupWindow(contentView,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        ListView community_list = (ListView)contentView.findViewById(R.id.community_list);

        communityAdapter = new CommunityAdapter(activity);
        community_list.setAdapter(communityAdapter);

        communitypop.setTouchable(true);
        //  ColorDrawable dw = new ColorDrawable(getResources().getColor(R.color.backgroud_light_I));
        communitypop.setBackgroundDrawable(new BitmapDrawable());


    }

    @Override
    public void doEvent() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        Log.e("requestCodereque===",""+requestCode);
        if(requestCode==11&&data!=null){
            String city = data.getStringExtra("property_city");
            String cityId = data.getStringExtra("property_city_id");
            String area = data.getStringExtra("property_area");
            String areaId = data.getStringExtra("property_area_id");
            String street = data.getStringExtra("property_street");
            String streetId = data.getStringExtra("property_street_id");
            etAddr.setText(city+area+street);
            if(requestVO==null){
                requestVO=new PropertyCommitVO();
            }

            if(!StringUtil.isBlank(cityId)){
                requestVO.setProperty_city(Integer.parseInt(cityId));
            }
            if(!StringUtil.isBlank(areaId)){
                requestVO.setProperty_area(Integer.parseInt(areaId));
            }
            if(!StringUtil.isBlank(streetId)){
                requestVO.setProperty_street(streetId);
            }

            LocalInfo.saveRentProperty(activity,requestVO);
            //  PublishedActivity.this.setResult(RESULT_OK);
        }
        //選擇圖片
        else if(requestCode==1&&data!=null){
            String selectedImages = data.getStringExtra("selectedImages");
            String imgtype = data.getStringExtra("type");

            ThingImageVO imageVO = new ThingImageVO();
            imageVO.setType(imgtype);

            if(mytype.get(imgtype)==null){
                mytype.put(imgtype,imageVO);
            }

            String[] type1 = new String[7];
            Iterator<Map.Entry<String, ThingImageVO>> it = mytype.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, ThingImageVO> entry = it.next();
                type1[Integer.parseInt(entry.getKey())]=entry.getValue().getType();
            }

            requestVO.setPropertyimg_sceimgtype(type1);

            String[] img = selectedImages.split(",");
            requestVO.setPropertyimg_path1(img);

            if(img.length<3){
                String[] myimg = new String[img.length+1];
                if(img.length==1){
                    myimg[0]=img[0];
                    myimg[1]="";
                }
                else if(img.length==2){
                    myimg[0]=img[0];
                    myimg[1]=img[1];
                    myimg[2]="";
                }
                mytype.get(imgtype).setImg(myimg);
            }
            else if(img.length==3){
                mytype.get(imgtype).setImg(img);
            }

            fillImg(null);
            LocalInfo.saveRentProperty(activity,requestVO);

        }

    }
    private class CommunityAdapter extends BaseAdapter {

        private LayoutInflater mInflater;
        public CommunityAdapter(Context context){
            this.mInflater = LayoutInflater.from(context);
        }
        @Override
        public int getCount() {
            return communityList.size();
        }

        @Override
        public Object getItem(int i) {
            return communityList.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            View  convertView = mInflater.inflate(R.layout.txt_item, null);
            final RentVO obj = communityList.get(i);
            TextView txt_content = (TextView)convertView.findViewById(R.id.txt_content);
            txt_content.setText(obj.getName());
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    etCommunity.setText(obj.getName());
                    requestVO.setProperty_community(obj.getSeq());
                    LocalInfo.saveProperty(activity,requestVO);
                    if (communitypop != null && communitypop.isShowing()) {
                        communitypop.dismiss();
                    }
                }
            });
            return convertView;
        }
    }
    private class ImageLoopAdapter extends LoopPagerAdapter {

        private String[] imgs=null;
        private String mytype;
        public ImageLoopAdapter(RollPagerView viewPager, String[] imgs,String type) {

            super(viewPager);
            this.imgs=imgs;
            mytype=type;
        }

        @Override
        public View getView(ViewGroup container, final int position) {
            SimpleDraweeView view = new SimpleDraweeView(container.getContext());
            view.setScaleType(ImageView.ScaleType.CENTER_CROP);
            if(StringUtil.isBlank(imgs[position])){
                view.setLayoutParams(new ViewGroup.LayoutParams(20, 20));
                view.setImageResource(R.mipmap.btn_est_upload_nor2x);
            }
            else{
//                view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
//                view.setImageURI(Uri.parse("file://"+imgs[position].toString()));
                ImageLoader.loadFile(view,imgs[position].toString(),200,200);
            }

            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PublishedImageActivity.gotoActivity(activity,mytype,parent,type,"");
                }
            });
            return view;

        }

        @Override
        public int getRealCount() {
            return imgs.length;
        }


    }
}
